<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
$records_perpage = 20;//每页显示20条记录
$data = array();//记录真正在页面上输出的总数据
$page = trim($_GET['_p']);
$page = empty($page) ? 1 : $page;
$page = intval($page);
if(!is_numeric($page) || $page <= 0)
{
	$page = 1;
}
?>
<script type="text/javascript">
function del_process(tpl_id)
{
	if(confirm("确定要删除此模板流程吗？"))
	{
		_ajax_request("job", 
		        "doDeleteProcess", 
		        {
		            id: tpl_id
		        }, 
		        on_delete_success, 
		        on_delete_failure);
	}
}

function on_delete_success(response)
{
	response1 = eval("("+response+")");
	var stat = document.getElementById("stat");
	if(response1.result == 'ok')
	{
		alert(response1.sucmsg);
		stat.innerHTML = "OK，正在重定向......";
		reloadPage();
	}
	else if(response1.result == 'error')
	{
		stat.innerHTML = response1.errmsg;
	}
}

function on_delete_failure(response)
{
	var stat = document.getElementById("stat");
	stat.innerHTML = response;
}

function showProcess(tpl_id,tpl_status)
{
	window.open('index.php?id='+tpl_id+'&status='+tpl_status+'&_m=job&_a=doViewProcess', '模板流程图', 'height=1085, width=470, top=100,left=150, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no, alwaysRaised=yes , copyhistory=no');
}
</script>
<?php
$stack = array();
$flag_show = false;

if(!empty($assignTemplate_address))
{
	echo "<p style='margin:20px 0px 3px 0px'><a style='font-size:12px;' href='$assignTemplate_address'>新建模板信息</a></p>";
	$flag_show = true;
}
?>
<?php 
if($isEmpty == 1)
{
	echo "Data is empty.";
}
else
{
?>
<style type="text/css">
table td {
	 text-align:left;
}
<?php 
if(!$flag_show)
{
	echo "table {margin-top:20px}";
}
?>
</style>
<div id="stat" style="display:none;"></div>
<table width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#4c4c4c">
<tr>
<td class="table_title">序号</td>
<td class="table_title">模板名</td>
<td class="table_title">模板行业</td>
<td class="table_title">三级域名</td>
<td class="table_title">设计人员</td>
<td class="table_title">状态</td>
<td class="table_title">操作</td>
</tr>
<?php
$user_stacks = array();
if(!empty($users))
{
	foreach($users as $k => $v)
	{
		$user_stacks[$v['u_id']] = $v['u_name'];
	}
}

$i = 1;
foreach($templates as $v)
{
	foreach($v as $k1 => $v1)
	{
		if(in_array($v1['tpl_id'], $stack)) continue;//不允许显示重复记录
		
		$stack[] = $v1['tpl_id'];
		
		$t_catory_id = $v1['tpl_category_id'];
		$t_catory = $template_categories[$t_catory_id];
		$t_status = $status[$v1['tpl_status']];
		$t_designer = $user_stacks[$v1['tpl_designer_id']];
		$tpl_domain = (empty($v1['tpl_domain'])) ? '-' : $v1['tpl_domain'];
		if(!(strpos($tpl_domain, 'http') === false))
		{
			$length = strlen($tpl_domain) - 7;
			$tpl_domain = substr($tpl_domain,-1 * $length,$length); 
		}
		

		$data[$i]['tpl_name'] = $v1['tpl_name'];
		$data[$i]['t_catory'] = $t_catory;
		$data[$i]['tpl_domain'] = $tpl_domain;
		$data[$i]['t_designer'] = $t_designer;
		$data[$i]['t_status'] = $t_status;
		$data[$i]['tpl_id'] = $v1['tpl_id'];
		$data[$i]['tpl_status'] = $v1['tpl_status'];

		$i++;
	}
}
$j = 1;
for($i = ($page - 1) * $records_perpage + 1;$i <= $page * $records_perpage;$i++)
{
	if(empty($data[$i]['tpl_name'])) break;
	if($showCancelButton)
	{
		echo "<tr><td>$j</td><td>{$data[$i]['tpl_name']}</td><td>{$data[$i]['t_catory']}</td><td><a target='_blank' href='http://{$data[$i]['tpl_domain']}'>{$data[$i]['tpl_domain']}</a></td><td>{$data[$i]['t_designer']}</td><td>{$data[$i]['t_status']}</td><td><a title='编辑' href='index.php?_m=job&_a=editTemplatePage&tpl_id={$data[$i]['tpl_id']}'><img style='border:none;' src='./images/edit.gif'/></a><a onclick='showProcess({$data[$i]['tpl_id']},{$v1['tpl_status']});' title='流程图' href='#'><img style='border:none;width:16px;height:16px;' src='./images/process.png'/></a>&nbsp;<a onclick='del_process({$data[$i]['tpl_status']});' title='撤销流程' href='#'><img style='border:none;' src='./images/cross.gif'></a></td></tr>";
	}
	else
	{
		echo "<tr><td>$j</td><td>{$data[$i]['tpl_name']}</td><td>{$data[$i]['t_catory']}</td><td><a target='_blank' href='http://{$data[$i]['tpl_domain']}'>{$data[$i]['tpl_domain']}</a></td><td>{$data[$i]['t_designer']}</td><td>{$data[$i]['t_status']}</td><td><a title='编辑' href='index.php?_m=job&_a=editTemplatePage&tpl_id={$data[$i]['tpl_id']}'><img style='border:none;' src='./images/edit.gif'/></a><a onclick='showProcess({$data[$i]['tpl_id']},{$data[$i]['tpl_status']});' title='流程图' href='#'><img style='border:none;width:16px;height:16px;' src='./images/process.png'/></a></td></tr>";
	}
	$j++;
}
?>
</table>
<?php
$n = count($data);
$amount_page = $n / $records_perpage;//总页数
$amount_page = intval($amount_page);
if($n % $records_perpage > 0) $amount_page++;
$str1 = '';
if(($page == 1 && $n / $records_perpage <= 1) || ($page == $amount_page && $page == 1))
{
	$str1 = "<a href='index.php?_m=job&_a=myJobPage&_p=1'>首页</a>|第{$page}页|<a href='index.php?_m=job&_a=myJobPage&_p={$amount_page}'>尾页</a>";
}
elseif($page == 1 && $n / $records_perpage > 1)
{
	$page_plus = $page + 1;
	$str1 = "<a href='index.php?_m=job&_a=myJobPage&_p=1'>首页</a>|第{$page}页|<a href='index.php?_m=job&_a=myJobPage&_p=$page_plus'>下一页</a>|<a href='index.php?_m=job&_a=myJobPage&_p={$amount_page}'>尾页</a>";
}
elseif($page == $amount_page && $page != 1)
{
	$page_minus = $page - 1;
	$str1 = "<a href='index.php?_m=job&_a=myJobPage&_p=1'>首页</a>|<a href='index.php?_m=job&_a=myJobPage&_p=$page_minus'>上一页</a>|第{$page}页|<a href='index.php?_m=job&_a=myJobPage&_p={$amount_page}'>尾页</a>";
}
else
{
	$page_plus = $page + 1;
	$page_minus = $page - 1;
	$str1 = "<a href='index.php?_m=job&_a=myJobPage&_p=1'>首页</a>|<a href='index.php?_m=job&_a=myJobPage&_p=$page_minus'>上一页|</a>|第{$page}页|<a href='index.php?_m=job&_a=myJobPage&_p=$page_plus'>下一页</a>|<a href='index.php?_m=job&_a=myJobPage&_p={$amount_page}'>尾页</a>";
}
echo "<div style='text-align:center;font-size:12px;'>{$str1}</div>";
}
?>